package net.hky365.shop.module.system.api.tenant;

import jakarta.annotation.Resource;
import net.hky365.shop.framework.tenant.core.api.tenant.TenantApi;
import net.hky365.shop.module.system.api.tenant.dto.TenantDTO;
import net.hky365.shop.module.system.convert.tenant.TenantConvert;
import net.hky365.shop.module.system.service.tenant.TenantService;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 多租户的 API 实现类
 *
 * @author 芋道源码
 */
@Service
public class TenantApiImpl implements TenantApi, TenantInfoApi {

    @Resource
    private TenantService tenantService;

    @Override
    public List<Long> getTenantIdList() {
        return tenantService.getTenantIdList();
    }

    @Override
    public void validateTenant(Long id) {
        tenantService.validTenant(id);
    }

    @Override
    public TenantDTO getTenant(long id) {
        return TenantConvert.INSTANCE.convert(tenantService.getTenant(id));
    }

    @Override
    public List<TenantDTO> getTenantList(Collection<Long> tenantIds) {
        return tenantService.getTenantList(tenantIds).stream().map(TenantConvert.INSTANCE::convert).collect(Collectors.toList());
    }

    @Override
    public List<TenantDTO> getTenantCachedList() {
        return tenantService.getTenantList().stream().map(TenantConvert.INSTANCE::convert).collect(Collectors.toList());
    }
}
